﻿using System;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using System.Text;
using Texfina.Core.Common;
using Texfina.Common.Mg;
using Texfina.Core.Web;
using Texfina.Core.Data;
using Texfina.Entity.Rh;
using Texfina.Entity.Mg;
using Texfina.Entity.Sy;
using RHBOQry = Texfina.BOQry.Rh;
using MGBOQry = Texfina.BOQry.Mg;
using RHBORpt = Texfina.BORpt.Rh;
using RHBOMnt = Texfina.BOMnt.Rh;
using SYBOQry = Texfina.BOQry.Sy;
using CrystalDecisions.CrystalReports.Engine;
using System.IO;
using CrystalDecisions.Shared;
using System.Drawing;
using System.Drawing.Printing;
using System.Globalization;

namespace RH
{
   public partial class wfBoletaTrabRpt : EditPage
   {
      private Font printFont;
      private int _indexRow = 0;
      private int _NumberPage = 0;

      protected void Page_Load(object sender, EventArgs e)
      {
         if (this.IsPostBack)
         {
            this.LoadInPostBack();
            return;
         }
         this.LoadData();

      }

      public override void LoadInPostBack()
      {
         this.RegisterGeneralScripts();
      }

      public override void LoadInitialSettings()
      {
         this.FormEditAction = FormEditAction.Edit;
         this.SetInitialTitle("Boletas de Pago");
      }

      public override void LoadListControls()
      {
         ETablaGenDet objEDet = new ETablaGenDet();
         ECCosto objECCosto = new ECCosto();

         IBOQuery objBOCCosto = (IBOQuery)WCFHelper.GetObject<IBOQuery>(typeof(MGBOQry.CCosto));
         MGBOQry.ITablaGen objBOI = (MGBOQry.ITablaGen)WCFHelper.GetObject<MGBOQry.ITablaGen>(typeof(MGBOQry.TablaGen));

         objEDet.IdTabla = ConstMultitabla.MES;
         DataTable dt = objBOI.GetDetailByList(objEDet);
         WebHelper.LoadListControl(ddlidMes, dt, "dsDescrip", "idCodigo", ConstCustomFirstListItem.ITEM_ALL);

         objEDet.IdTabla = ConstMultitabla.FORMA_PAGO;
         dt = objBOI.GetDetailByList(objEDet);
         WebHelper.LoadListControl(ddlidFormaPago, dt, "dsDescrip", "idCodigo", ConstCustomFirstListItem.ITEM_ALL);

         //objECCosto.IdEmpresa = Session[ConstSessionVar.EMPRESA].ToString();
         //dt = objBOCCosto.GetList(objECCosto);
         //WebHelper.LoadListControl(ddlidCCosto, dt, "dsCCosto", "idCCosto", ConstCustomFirstListItem.ITEM_ALL);

         SYBOQry.IEmpresa objBOEmp = (SYBOQry.IEmpresa)WCFHelper.GetObject<SYBOQry.IEmpresa>(typeof(SYBOQry.Empresa));
         EEmpEstable objEEmp = new EEmpEstable();
         objEEmp.IdEmpresa = Session[ConstSessionVar.EMPRESA].ToString();
         dt = objBOEmp.GetEstablecimientos(objEEmp);
         WebHelper.LoadListControl(ddlidEstable, dt, "dsEstable", "idEstable", ConstCustomFirstListItem.ITEM_ALL);

         IBOQuery objBOUNego = (IBOQuery)WCFHelper.GetObject<IBOQuery>(typeof(MGBOQry.UNegocio));
         EUNegocio objEUNeg = new EUNegocio();
         objEUNeg.IdEmpresa = Session[ConstSessionVar.EMPRESA].ToString();
         dt = objBOUNego.GetList(objEUNeg);
         WebHelper.LoadListControl(ddlidUniNego, dt, "dsUNegocio", "idUNegocio", ConstCustomFirstListItem.ITEM_ALL);


      }
      protected void ddlidUNegocio_SelectedIndexChanged(object sender, EventArgs e)
      {
         ddlidCCosto.Items.Clear();
         EUNegocio objEUNeg = new EUNegocio();
         MGBOQry.IUNegocio objBOUNego = (MGBOQry.IUNegocio)WCFHelper.GetObject<MGBOQry.IUNegocio>(typeof(MGBOQry.UNegocio));
         objEUNeg.IdEmpresa = Session[ConstSessionVar.EMPRESA].ToString();
         objEUNeg.IdUNegocio = ddlidUniNego.SelectedItem.Value;
         DataTable dt = objBOUNego.GetCCostoXUNegocio(objEUNeg);
         WebHelper.LoadListControl(ddlidCCosto, dt, "dsCCosto", "idCCosto", true, true);
      }
      public override void DataToControls()
      {


      }

      public override void RegisterGeneralScripts()
      {

         StringBuilder sb = new StringBuilder();

         sb.AppendLine("var varRet = modalDialog('wfPersonal.aspx',725,400);");
         sb.AppendLine("if(varRet==null)");
         sb.AppendLine("return false;");
         sb.AppendLine("ctl = document.getElementById('" + this.hdnidPersonalIni.ClientID + "');");
         sb.AppendLine("ctl.value = varRet[0];");
         sb.AppendLine("ctl = document.getElementById('" + this.txtidPersonalIni.ClientID + "');");
         sb.AppendLine("ctl.value = varRet[1];");
         this.txtidPersonalIni.OnClientClick = sb.ToString();

         sb = new StringBuilder();

         sb.AppendLine("var varRet = modalDialog('wfPersonal.aspx',725,400);");
         sb.AppendLine("if(varRet==null)");
         sb.AppendLine("return false;");
         sb.AppendLine("ctl = document.getElementById('" + this.hdnidPersonalFin.ClientID + "');");
         sb.AppendLine("ctl.value = varRet[0];");
         sb.AppendLine("ctl = document.getElementById('" + this.txtidPersonalFin.ClientID + "');");
         sb.AppendLine("ctl.value = varRet[1];");
         this.txtidPersonalFin.OnClientClick = sb.ToString();

         sb = new StringBuilder();

         sb.AppendLine("var varRpta = isEmptyControl('" + this.ddlidMes.ClientID + "','Seleccione el Mes.');");
         sb.AppendLine("if(varRpta==true)");
         sb.AppendLine("return !varRpta;");
         sb.AppendLine("var varRpta = isEmptyControl('" + this.ddlidFormaPago.ClientID + "','Seleccione la forma de Pago.');");
         sb.AppendLine("if(varRpta==true)");
         sb.AppendLine("return !varRpta;");
         sb.AppendLine("var varRet = modalDialog('wfProcPlani.aspx?IdMes=' + document.getElementById('" + this.ddlidMes.ClientID + "').value + '&IdFormaPago=' + document.getElementById('" + this.ddlidFormaPago.ClientID + "').value,725,400);");
         sb.AppendLine("if(varRet==null)");
         sb.AppendLine("return false;");
         sb.AppendLine("ctl = document.getElementById('" + this.hdnidPlanilla.ClientID + "');");
         sb.AppendLine("ctl.value = varRet[0];");
         sb.AppendLine("ctl = document.getElementById('" + this.hdnnuProcAnual.ClientID + "');");
         sb.AppendLine("ctl.value = varRet[4];");
         sb.AppendLine("ctl = document.getElementById('" + this.txtidPlanilla.ClientID + "');");
         sb.AppendLine("ctl.value = varRet[3] + ' - ' + varRet[2] + ' - ' + varRet[1] + ' - ' + varRet[4];");
         this.txtidPlanilla.OnClientClick = sb.ToString();

         sb = new StringBuilder();

         sb.AppendLine("var varRpta = isEmptyControl('" + this.ddlidMes.ClientID + "','Seleccione el Mes.');");
         sb.AppendLine("if(varRpta==true)");
         sb.AppendLine("return !varRpta;");
         sb.AppendLine("var varRpta = isEmptyControl('" + this.ddlidFormaPago.ClientID + "','Seleccione la forma de Pago.');");
         sb.AppendLine("if(varRpta==true)");
         sb.AppendLine("return !varRpta;");
         sb.AppendLine("var varRet = modalDialog('wfProcPlani.aspx?IdMes=' + document.getElementById('" + this.ddlidMes.ClientID + "').value + '&IdFormaPago=' + document.getElementById('" + this.ddlidFormaPago.ClientID + "').value,725,400);");
         sb.AppendLine("if(varRet==null)");
         sb.AppendLine("return false;");
         sb.AppendLine("if(varRet[0] != document.getElementById('" + this.hdnidPlanilla.ClientID + "').value){");
         sb.AppendLine("alert('No puede seleccionar un tipo de planilla diferente.'); return false;}");
         sb.AppendLine("else if(varRet[4] < document.getElementById('" + this.hdnnuProcAnual.ClientID + "').value){");
         sb.AppendLine("alert('No puede seleccionar una Planilla con numero de proceso menor.'); return false;}");
         sb.AppendLine("ctl = document.getElementById('" + this.hdnidPlanilla.ClientID + "');");
         sb.AppendLine("ctl.value = varRet[0];");
         sb.AppendLine("ctl = document.getElementById('" + this.hdnnuProcAnualFin.ClientID + "');");
         sb.AppendLine("ctl.value = varRet[4];");
         sb.AppendLine("ctl = document.getElementById('" + this.txtidPlanillaFin.ClientID + "');");
         sb.AppendLine("ctl.value = varRet[3] + ' - ' + varRet[2] + ' - ' + varRet[1] + ' - ' + varRet[4];");
         this.txtidPlanillaFin.OnClientClick = sb.ToString();

         //sb = new StringBuilder();

         //sb.AppendLine("ctl = document.getElementById('" + this.txtidPersonal.ClientID + "');");
         //sb.AppendLine("ctl.value = '';");
         //sb.AppendLine("ctl = document.getElementById('" + this.ddlidCCosto.ClientID + "');");
         //sb.AppendLine("ctl.value = '';");
         //this.bttClear.OnClientClick = sb.ToString();

         sb = new StringBuilder();

         sb.AppendLine("function validateEditForm(key){");
         sb.AppendLine("      var varRpta = isEmptyControl('" + this.txtidPlanilla.ClientID + "','Seleccione la Planilla');");
         sb.AppendLine("      if(varRpta==true)");
         sb.AppendLine("      return !varRpta;");
         sb.AppendLine("__doPostBack('" + this.mnuToolbar.UniqueID + "',key);");
         sb.AppendLine("}");


         ScriptManager.RegisterStartupScript(this, this.GetType(), "ScriptRegister", sb.ToString(), true);
      }

      public void RegisterEditPopupScripts()
      {

      }

      protected void mnuToolbar_MenuItemClick(Object sender, MenuEventArgs e)
      {
         if (e.Item == null)
            return;

         switch (e.Item.Value)
         {

            case ConstMenuToolbarValue.BUTTON_PREVIEW:
               PreviewReport(e.Item.Value);
               break;
            case ConstMenuToolbarValue.BUTTON_EXPORT:
               ExportReport(e.Item.Value);
               break;
            case ConstMenuToolbarValue.BUTTON_PRINT:
               PrintReport(e.Item.Value);
               break;
         }

      }

      public void PreviewReport(string key)
      {
         ReportDocument objRpt = new ReportDocument();

         DataSet ds = (DataSet)this .GetDataReport(key);

         DataTable dt = ds.Tables[0];

         string NomRep="";

         if (ds.Tables[0].Rows.Count == 0)
         {
            this.hdnMsgOPB.Value = this.CreatePostbackMessage(0, "No se encotraron Resultados", "");
            return;
         }

         if ((dt.Rows[0]["idTipoTrab"].ToString() != "999") && (dt.Rows[0]["idTipoTrab"].ToString() != "023"))
         {
            NomRep = "BoletaTrabajador";
            objRpt.Load(this.MapPath(ConstSistema.ROOT_FOLDER_PATH + "/BoletaTrabajador.rpt"));
         }
         else {

            if (dt.Rows[0]["idTipoTrab"].ToString() == "999")
            {
               NomRep = "BoletaFLJ";
               objRpt.Load(this.MapPath(ConstSistema.ROOT_FOLDER_PATH + "/BoletaFLJ.rpt"));
            }

            if (dt.Rows[0]["idTipoTrab"].ToString() == "023")
            {
               NomRep = "BoletaSENATI";
               objRpt.Load(this.MapPath(ConstSistema.ROOT_FOLDER_PATH + "/BoletaSENATI.rpt"));
            }
         }


         objRpt.SetDataSource(ds.Tables[0]);

         MemoryStream ms = new MemoryStream();

         Response.Clear();

         ms = (MemoryStream)objRpt.ExportToStream(ExportFormatType.PortableDocFormat);
         objRpt.Dispose();
         objRpt = null;

         Response.AddHeader("Content-Disposition", "attachment;filename=" + NomRep + ".pdf");
         Response.Buffer = true;
         Response.ContentType = "application/pdf";

         ms.WriteTo(Response.OutputStream);
         Response.Flush();
         Response.End();

      }

      public override void PrintReport(string key)
      {

         ReportDocument objRpt = new ReportDocument();

         DataSet ds = (DataSet)this.GetDataReport(key);

         if (ds.Tables[0].Rows.Count == 0)
         {
            this.hdnMsgOPB.Value = this.CreatePostbackMessage(0, "No se encotraron Resultados", "");
            return;
         }

         this.DataSource = ds.Tables[0];
         try
         {
            //string strRuta = this.MapPath(ConstSistema.ROOT_UPLOADFOLDER_PATH + "/BolTraba_" + Session[ConstSessionVar.USERID].ToString() + DateTime.Now.ToString("MMdd") + ".xps");
            printFont = new Font("Roman", 8);
            PrintDocument pd = new PrintDocument();
            pd.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("new size", 1063, 551);
            pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
            //pd.PrinterSettings.PrintToFile = true;
            //pd.PrinterSettings.PrintFileName = strRuta;
            //pd.PrinterSettings.PrinterName = "PrinterTexfinaErp_v2"; 
            pd.Print();

            //Response.Clear();
            //Response.Buffer = true;
            //Response.ContentType = "application/vnd.ms-xpsdocument";
            //Response.AppendHeader("Content-Disposition", "attachment; filename=BoletadePago.xps");
            //Response.TransmitFile(strRuta);
            //Response.Flush();
            //Response.End();


         }
         finally
         {




         }

      }

      public override void ExportReport(string key)
      {
         DataSet ds = (DataSet)this.GetDataReport(key);
         if (ds.Tables[0].Rows.Count == 0)
         {
            this.hdnMsgOPB.Value = this.CreatePostbackMessage(0, "No se encotraron Resultados", "");
            return;
         }
         ExcelHelper.ToExcel(ds, "Data.xls", Response);

      }

      public override object GetDataReport(string key)
      {

         EBoletaPago objEDet = new EBoletaPago();
         RHBORpt.IPlanilla objBODet = (RHBORpt.IPlanilla)WCFHelper.GetObject<RHBORpt.IPlanilla>(typeof(RHBORpt.Planilla));
         objEDet.IdPeriodo = Session[ConstSessionVar.PERIODO].ToString();
         objEDet.IdEmpresa = Session[ConstSessionVar.EMPRESA].ToString();
         objEDet.IdForPago = this.ddlidFormaPago.SelectedItem.Value;
         objEDet.IdPlanilla = this.hdnidPlanilla.Value;
         objEDet.NuProcAnualIni = int.Parse(this.hdnnuProcAnual.Value);
         if (hdnnuProcAnualFin.Value != null)
            if (hdnnuProcAnualFin.Value == "")
               objEDet.NuProcAnualFin = int.Parse(this.hdnnuProcAnual.Value);
            else
               objEDet.NuProcAnualFin = int.Parse(this.hdnnuProcAnualFin.Value);
         else
            objEDet.NuProcAnualFin = int.Parse(this.hdnnuProcAnual.Value);


         if (this.txtidPersonalIni.Text == "")
            objEDet.IdPersonalIni = null;
         else
            objEDet.IdPersonalIni = this.hdnidPersonalIni.Value;

         if (this.txtidPersonalFin.Text == "")
            if (this.txtidPersonalIni.Text != "")
               objEDet.IdPersonalFin = this.hdnidPersonalIni.Value;
            else
               objEDet.IdPersonalFin = null;
         else
            objEDet.IdPersonalFin = null;

         if (this.ddlidEstable.SelectedItem.Value == "")
            objEDet.IdEstable = null;
         else
            objEDet.IdEstable = this.ddlidEstable.SelectedItem.Value;

         if (this.ddlidUniNego.SelectedItem.Value == "")
            objEDet.IdUNegocio = null;
         else
            objEDet.IdUNegocio = this.ddlidUniNego.SelectedItem.Value;

         if (this.ddlidCCosto.SelectedItem != null)
            if (this.ddlidCCosto.SelectedItem.Value == "")
               objEDet.IdCCosto = null;
            else
               objEDet.IdCCosto = this.ddlidCCosto.SelectedItem.Value;
         else
            objEDet.IdCCosto = null;

         DataSet ds = new DataSet();

         DataTable dt = null;

         dt = objBODet.GetBoletaTrabajadorPrint(objEDet);
         ds.Tables.Add(dt);

         return ds;


      }

      private void pd_PrintPage(object sender, PrintPageEventArgs ev)
      {
         float linesPerPage = 6;
         float yPos = 0;
         int count = 0;
         float leftMargin = 0;
         float topMargin = 22;
         string stridEmpleado = null;
         string strDecValue = "";
         RectangleF drawRect;
         StringFormat stringFormat = new StringFormat();
         // Calculate the number of lines per page.
         linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics);

         DataRow row = null;

         if (_indexRow < this.DataSource.Rows.Count)
         {
            row = this.DataSource.Rows[_indexRow];
            stridEmpleado = row["idPersonalGroup"].ToString();
            yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));

            ev.Graphics.DrawString(row["dsTipoTrab"].ToString(), printFont, Brushes.Black, 900, yPos);
            ev.Graphics.DrawString(row["dsPlanilla"].ToString() + " [ " + row["nuProcAnual"].ToString() + " ]  DESDE : " + (row["feDesde"].ToString() != "" ? DateTime.Parse(row["feDesde"].ToString()).ToString("dd/MM/yyyy") : row["feDesde"].ToString()) + "   -   HASTA : " + (row["feHasta"].ToString() != "" ? DateTime.Parse(row["feHasta"].ToString()).ToString("dd/MM/yyyy") : row["feHasta"].ToString()), printFont, Brushes.Black, 300, yPos);

            topMargin = 42;
            count++;
            yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));

            ev.Graphics.DrawString(stridEmpleado, printFont, Brushes.Black, 10, yPos);
            ev.Graphics.DrawString(row["dsApellNombres"].ToString(), printFont, Brushes.Black, 90, yPos);

            drawRect = new RectangleF(485, yPos - 6, 280, printFont.GetHeight(ev.Graphics) * 2);
            stringFormat.Alignment = StringAlignment.Near;
            ev.Graphics.DrawString(row["dsOcupa"].ToString(), printFont, Brushes.Black, drawRect, stringFormat);

            ev.Graphics.DrawString(row["nuDocIden"].ToString(), printFont, Brushes.Black, 800, yPos);
            ev.Graphics.DrawString(row["idCCosto"].ToString(), printFont, Brushes.Black, 910, yPos);

            topMargin = 78;
            count++;
            yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));

            ev.Graphics.DrawString(row["feIngpla"].ToString() != "" ? DateTime.Parse(row["feIngpla"].ToString()).ToString("dd/MM/yyyy") : row["feIngpla"].ToString(), printFont, Brushes.Black, 10, yPos);
            ev.Graphics.DrawString(row["mtRemu"].ToString(), printFont, Brushes.Black, 460, yPos);
            ev.Graphics.DrawString(row["dsAfp"].ToString(), printFont, Brushes.Black, 580, yPos);
            ev.Graphics.DrawString(row["nuCuspp"].ToString(), printFont, Brushes.Black, 850, yPos);

            DataRow[] dr = this.DataSource.Select("idPersonalGroup = '" + row["idPersonalGroup"].ToString() + "'");

            if (dr.Length > 0)
               foreach (DataRow drNew in dr)
               {
                  topMargin = 140;
                  count++;
                  yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
                  leftMargin = 5;
                  ev.Graphics.DrawString(drNew["dsConRemu"].ToString(), printFont, Brushes.Black, leftMargin, yPos);

                  if (drNew["nuHoras"].ToString() != null && drNew["nuHoras"].ToString() != "")
                  {
                     drawRect = new RectangleF(180, yPos, 100, printFont.GetHeight(ev.Graphics));
                     stringFormat.Alignment = StringAlignment.Far;
                     strDecValue = Math.Round(decimal.Parse(drNew["nuHoras"].ToString()), 2).ToString();
                     ev.Graphics.DrawString(strDecValue, printFont, Brushes.Black, drawRect, stringFormat);
                  }

                  if (drNew["mtCalculo"].ToString() != null && drNew["mtCalculo"].ToString() != "")
                  {
                     drawRect = new RectangleF(290, yPos, 100, printFont.GetHeight(ev.Graphics));
                     stringFormat.Alignment = StringAlignment.Far;
                     strDecValue = Math.Round(decimal.Parse(drNew["mtCalculo"].ToString()), 2).ToString();
                     ev.Graphics.DrawString(strDecValue, printFont, Brushes.Black, drawRect, stringFormat);
                  }

                  ev.Graphics.DrawString(drNew["dsConRemuRem"].ToString(), printFont, Brushes.Black, 430, yPos);

                  if (drNew["mtCalculoRetDed"].ToString() != null && drNew["mtCalculoRetDed"].ToString() != "" && drNew["mtCalculoRetDed"].ToString() != "0.0000")
                  {
                     drawRect = new RectangleF(640, yPos, 100, printFont.GetHeight(ev.Graphics));
                     stringFormat.Alignment = StringAlignment.Far;
                     strDecValue = Math.Round(decimal.Parse(drNew["mtCalculoRetDed"].ToString()), 2).ToString();
                     ev.Graphics.DrawString(strDecValue, printFont, Brushes.Black, drawRect, stringFormat);
                  }

                  if (drNew["mtCalculoApor"].ToString() != null && drNew["mtCalculoApor"].ToString() != "" && drNew["mtCalculoApor"].ToString() != "0.0000")
                  {
                     drawRect = new RectangleF(860, yPos, 100, printFont.GetHeight(ev.Graphics));
                     stringFormat.Alignment = StringAlignment.Far;
                     strDecValue = Math.Round(decimal.Parse(drNew["mtCalculoApor"].ToString()), 2).ToString();
                     ev.Graphics.DrawString(strDecValue, printFont, Brushes.Black, drawRect, stringFormat);
                  }

                  _indexRow++;
               }
            else
               _indexRow++;

            count = 1;
            topMargin = 400;
            count++;
            yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));

            drawRect = new RectangleF(290, yPos, 100, printFont.GetHeight(ev.Graphics));
            stringFormat.Alignment = StringAlignment.Far;
            ev.Graphics.DrawString(Math.Round(decimal.Parse(row["mtTotRemuMn"].ToString()), 2).ToString(), printFont, Brushes.Black, drawRect, stringFormat);

            drawRect = new RectangleF(640, yPos, 100, printFont.GetHeight(ev.Graphics));
            stringFormat.Alignment = StringAlignment.Far;
            ev.Graphics.DrawString(Math.Round(decimal.Parse(row["mtTotDescMn"].ToString()), 2).ToString(), printFont, Brushes.Black, drawRect, stringFormat);

            drawRect = new RectangleF(860, yPos, 100, printFont.GetHeight(ev.Graphics));
            stringFormat.Alignment = StringAlignment.Far;
            ev.Graphics.DrawString(Math.Round(decimal.Parse(row["mtTotAportMn"].ToString()), 2).ToString(), printFont, Brushes.Black, drawRect, stringFormat);

            count++;
            yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));

            drawRect = new RectangleF(290, yPos, 100, printFont.GetHeight(ev.Graphics));
            stringFormat.Alignment = StringAlignment.Far;
            ev.Graphics.DrawString(Math.Round(decimal.Parse(row["mtRedActMn"].ToString()), 2).ToString(), printFont, Brushes.Black, drawRect, stringFormat);

            drawRect = new RectangleF(640, yPos, 100, printFont.GetHeight(ev.Graphics));
            stringFormat.Alignment = StringAlignment.Far;
            ev.Graphics.DrawString(Math.Round(decimal.Parse(row["mtRedAntMn"].ToString()), 2).ToString(), printFont, Brushes.Black, drawRect, stringFormat);

            drawRect = new RectangleF(860, yPos, 100, printFont.GetHeight(ev.Graphics));
            stringFormat.Alignment = StringAlignment.Far;
            ev.Graphics.DrawString(Math.Round(decimal.Parse(row["mtNetoMn"].ToString()), 2).ToString(), printFont, Brushes.Black, drawRect, stringFormat);

         }


         // If more lines exist, print another page.
         if (stridEmpleado != null)
            ev.HasMorePages = true;
         else
            ev.HasMorePages = false;
      }
   }
}